import { getReviewList } from '../../../utils/requestApi.js'
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    currentTab: String,
    prDid: String
  },

  /**
   * 组件的初始数据
   */
  data: {
    imgUrl: app.data.imgurl,
    listData: [],  //页面数据
    scrollHeight: 0,
    page: 1,
  },

  pageLifetimes: {
    show: function () {
      wx.getSystemInfo({
        success: res=> {
          this.setData({ 
            scrollHeight: res.windowHeight,
            navHeight: app.data.navHeight,
          })
        }
      })
      this.initData();
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    initData: function () {
      let { prDid, page, listData } = this.data;
      getReviewList({
        action: 'LoadReviewYinLiu',
        PageSize: 10,
        pageIndex: page,
        ProductId: prDid
      }).then(res => {
        if (res.statusCode == 200 && res.data.Result.Data.length != 0) {
          res.data.Result.Data.forEach(item => {
            if (typeof item.Score == 'string') item.Score = parseInt(item.Score)
          })
          this.setData({
            listData: [...listData, ...res.data.Result.Data],
            page: page + 1
          })
        }
      })
    },
    
    //预览图片
    previewImage(e){
      let { listData } = this.data;
      let { imgindex, listindex } = e.currentTarget.dataset;
      wx.previewImage({
        current: listData[listindex].ImagesList[imgindex], // 当前显示图片的http链接
        urls: listData[listindex].ImagesList // 需要预览的图片http链接列表
      })      
    },

    //滚动
    onScrolltolower(e){
      this.initData()
    }
  }
})
